﻿@{
    ViewData["Title"] = "包含增删查改的Table页面";
    Layout = "~/Views/Shared/_LayuiTableEdit.cshtml";
}
<form id="searchForm" onsubmit="return false;">
    <div class="layui-input-inline">
        <input class="layui-input search_input" placeholder="请输入关键字" name="searchValue" autocomplete="off">
    </div>
    <div class="layui-input-inline">
        <a class="layui-btn layui-btn-normal" onclick="tableReload()">搜索</a>
    </div>
    <div class="layui-inline">
        <button type="reset" class="layui-btn layui-btn-danger">重置</button>
    </div>
</form>
<script type="text/html" id="tableBar">
    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>

<script type="text/html" id="IsSubmit">
    {{#  if(d.IsSubmit == 1 ){ }}
    <span style="color: #F581B1;">是</span>
    {{#  } else { }}
    否
    {{#  } }}
</script>
<script type="text/html" id="IsEnableTpl">
    <input type="checkbox" name="IsEnable" value="true" RecordId="{{d.Id}}" lay-skin="switch" lay-text="开启|关闭" lay-filter="IsEnableEvent" {{ d.IsEnable ? 'checked' : '' }}>
</script>

<script type="text/html" id="toolbar">
    <button class="layui-btn " onclick="add()">新增</button>
</script>
<table id="mainTable" lay-filter="demo"></table>
<script>
    addLayuiUseEvent(function () {
        tableRender({
            where: getQueryWhere()
            , page: true
            , toolbar: '#toolbar'
            , url: '@ViewBag.ListUrl'
            , cols: [[
                { type: 'numbers', title: '序号' }
                , { field: 'Column1', width: 200, align: 'center', title: '列1' }
                , { field: 'Column2', width: 90, align: 'center', title: '列2' }
                , { field: 'IsSubmit', width: 90, align: 'center', title: '自定义样式列', templet: '#IsSubmit' }
                , { field: 'IsEnable', width: 100, align: 'center', title: '是否开启',templet: '#IsEnableTpl'}
                , { fixed: 'right', width: 150, align: 'center', title: '操作', toolbar: '#tableBar' }

            ]]
        });

        var form = layui.form;
        //监听操作
        form.on('switch(IsEnableEvent)', function (obj) {
            var switchState = obj.elem.checked ;
            var id = $(obj.elem).attr("RecordId");
            jqJsonPost("/api/apiExamineRecord/updateEnable",
                { Id : id, IsEnable:switchState},
                function (data) {
                    layer.msg(data.msg);
                    if (data.code != 0) {
                        obj.elem.checked = false;
                        form.render();
                    }
                });
        });
    });
</script>